﻿$(function () {
    //2.初始化页面
    var oPageInit = new PageInit();
    oPageInit.Init();
    //oPageInit.LoadType("type", "#sel_type", '', true);
});

var PageInit = function () {
    var oInit = new Object();
    var postdata = {};

    var table, form, layer, rate, element, upload;
    var active;
    var tableId = 'tb_list';
    var table_investor = 'tb_investor';
    //初始化页面上面的按钮事件
    oInit.Init = function () {

        $(document).on('click', '[name="a_title"]', function () {
            var htid = $(this).data('htid');
            if (!$(this).hasClass('layui-btn-disabled')) {
                var title = $(this).html();
                oInit.LoadHonorFile(title, htid);
            }
        });

        $(document).on('keyup', '#ep_basic_data_Tbody [type="number"]', function () {
            oInit.DataAvgCalculate();
        });

        $('#btn_investor_add').click(function () {
            oInit.investorData(null);
        });
        $('#btn_product_add').click(function () {
            oInit.productData(null);
        });
        $('#btn_support_add').click(function () {
            oInit.supportData(null);
        });


        $('#btn_investor_del').click(function () {
            var chk_count = $('#tb_investor_body [name="rdo"]:checked').length
            if (chk_count == 1) {
                $('#tb_investor_body [name="rdo"]:checked').closest('tr').remove();
            } else {
                toastr.error('请选择数据!');
            }
        });
        $('#btn_product_del').click(function () {
            var chk_count = $('#tb_product_body [name="rdo"]:checked').length
            if (chk_count == 1) {
                $('#tb_product_body [name="rdo"]:checked').closest('tr').remove();
            } else {
                toastr.error('请选择数据!');
            }
        });
        $('#btn_support_del').click(function () {
            var chk_count = $('#tb_support_body [name="rdo"]:checked').length
            if (chk_count == 1) {
                $('#tb_support_body [name="rdo"]:checked').closest('tr').remove();
            } else {
                toastr.error('请选择数据!');
            }
        });


        layui.use(['table', 'form', 'rate', 'element', 'upload'], function () {
            table = layui.table
          , form = layui.form
          , layer = layui.layer
          , rate = layui.rate
          , element = layui.element
          , upload = layui.upload;

            var investorData = oInit.GetInvestorData(); //获得需要展现的 主要股东/出资人信息
            var productData = oInit.GetProductData(); //获得主营产品数据
            var personnel_infoData = oInit.GetPersonnelData(); //获得人员基本信息
            var gov_support_infoData = oInit.GetSupportData(); //获得政府资助情况

            oInit.loadData();
            oInit.loadPageData();
            oInit.investorData(investorData);
            oInit.productData(productData);
            oInit.personnelData(personnel_infoData);
            oInit.supportData(gov_support_infoData);
            oInit.InitUpload('btnYYZZ');

            form.on('select(ht_is)', function (data) {
                var ht_type = $(data.elem).data('httype');
                var ht_id = $(data.elem).data('htid');

                if (ht_type == 1) {
                    if (data.value == 1) {
                        $('[name="a_title"][data-htid="' + ht_id + '"]').removeClass('layui-btn-disabled');
                    } else {
                        $('[name="a_title"][data-htid="' + ht_id + '"]').addClass('layui-btn-disabled');
                    }
                    $('a[data-htid="' + ht_id + '"]').click();
                }
                if (ht_type == 2) {
                    if (data.value == 1) {
                        $('[name="ht_content"][data-pid="' + ht_id + '"]').prop('readonly', false).removeClass('layui-btn-disabled');
                    } else {
                        $('[name="ht_content"][data-pid="' + ht_id + '"]').prop('readonly', true).addClass('layui-btn-disabled');
                    }
                }
            });

            //监听多选框点击事件  主要是通过 lay-filter="switchRadio"  来监听
            form.on('radio(switchRadio)', function (data) {
                //console.log(data);　　//打印当前选择的信息
                //var value = data.value;   //获取选中的value值 加载数数据时会将radio checkbox的value置空，所以只能用data-value获取
                //debugger
                var name = data.elem.name;
                var value = $(data.elem).data('value');
                var child_obj = $('[name="' + name + '_child"]');
                if (child_obj.length > 0) {
                    if (value == 1) {
                        //child_obj.prop('readonly', false);
                        child_obj.prop('disabled', false);
                        child_obj.css('background', '');
                        child_obj.parent().css('background', '');
                        //child_obj.next().removeClass('layui-radio-disbaled layui-disabled');    //radio 禁用样式
                        //child_obj.next().removeClass('layui-checkbox-disbaled layui-disabled'); //checkbox 禁用样式
                    } else {
                        //child_obj.prop('readonly', true);
                        child_obj.prop('disabled', true);
                        child_obj.css('background', '#D3D3D3');
                        child_obj.parent().css('background', '#D3D3D3');
                        //child_obj.next().addClass('layui-radio-disbaled layui-disabled');       //radio 禁用样式
                        //child_obj.next().addClass('layui-checkbox-disbaled layui-disabled');    //checkbox 禁用样式
                    }
                }
            });

            //企业基本情况-提交
            form.on('submit(ep_base_info)', function (data) {
                //处理多个相同的 表明.字段的属性 如：ep_investor.inv_name = 1;ep_investor.inv_name = 2; 处理成 ep_investor = [{inv_name:1},{inv_name:2}]
                var formArray = $(data.form).serializeArray();
                //保存-主要股东/出资人信息
                var formObject = GetFormList(formArray, 'ep_investor', 'inv_name');
                data.field = formObject;

                GetFormCheckboxRadio(data);
                //console.log(data.field)
                oInit.Save(data.field);
                return false;
            });
            //产品信息-提交
            form.on('submit(ep_product_info)', function (data) {
                var formArray = $(data.form).serializeArray();
                var formObject = GetFormList(formArray, 'ep_business_product', 'prod_name');
                data.field = formObject;
                oInit.Save(data.field);
                //oInit.Save($(data.form).serializeObject());
                return false;
            });
            //企业人员统计-提交
            form.on('submit(ep_personnel_info)', function (data) {
                var formArray_obj = $(data.form).serializeObject();
                var formArray = $(data.form).serializeArray();
                var formObject = GetFormList(formArray, 'ep_personnel_info', 'pi_type');
                formArray_obj.ep_personnel_info = formObject.ep_personnel_info;
                oInit.Save(formArray_obj);
                //oInit.Save($(data.form).serializeObject());
                return false;
            });
            ////企业人员统计-提交 old
            //form.on('submit(ep_personnel_stats)', function (data) {
            //    oInit.Save($(data.form).serializeObject());
            //    return false;
            //});
            //政府资助情况-提交
            form.on('submit(ep_gov_support)', function (data) {
                var formArray = $(data.form).serializeArray();
                var formObject = GetFormList(formArray, 'ep_gov_support', 'sup_type');
                data.field = formObject;
                //console.log(data.field)
                oInit.Save(data.field);
                //oInit.Save($(data.form).serializeObject());
                return false;
            });

            //企业近三年基本数据-提交
            form.on('submit(ep_basic_data)', function (data) {
                //var fields = $(data.form).serialize();
                var formArray = $(data.form).serializeArray();
                var formObject = GetFormList(formArray, 'ep_basic_data', 'id');
                oInit.Save(formObject);
                return false;
            });
            //企业知识产权情况-提交
            form.on('submit(ep_ip_info)', function (data) {
                oInit.Save($(data.form).serializeObject());
                return false;
            });
            //企业认证资质获得情况-提交
            form.on('submit(ep_cert_qualified)', function (data) {
                oInit.Save($(data.form).serializeObject());
                return false;
            });

            //企业荣誉获得情况-提交
            form.on('submit(ep_ht)', function (data) {
                var formArray = $(data.form).serializeArray();
                var formObject = GetFormList(formArray, 'ep_ht', 'id');
                oInit.Save(formObject);
                return false;
            });

            //rate.render({
            //    elem: '#test8'
            //    , length: 10
            //    , value: 7.5 //初始值
            //    , half: true //开启半星
            //});
        });
    }

    //初始化Table,加载数据
    oInit.loadData = function () {

        //方法级渲染
        table.render({
            elem: '#' + tableId
            , id: tableId
        , loading: true
        , toolbar: '#toolbar'
        , defaultToolbar: ['']  //工具栏右侧的图标按钮
        , url: Root + 'FZParam/GetBaseParam'
        , cols: [[
        { checkbox: true, fixed: true }, { type: 'numbers', title: '序号' }
        , { field: 'id', title: 'ID', sort: true, fixed: true, hide: true }
        , {
            field: 'name',
            title: '参数名称'
        }, {
            field: 'descs',
            title: '描述'
        }, {
            field: 'type',
            title: '参数类别',
            formatter: function (value, row, index) {
                return ShowParamType(value);
            }
        }
            , { fixed: 'right', title: '操作', toolbar: '#tableBar', width: 120 }
        ]]
        , page: true
        , limit: 10
            //, cellMinWidth: 80
        , height: 'full-300'
        });

        var $ = layui.$;
        active = {
            reload: function () {
                var txt_search = $('#txt_search');
                var temp = {
                    SearchText: txt_search.val(),
                    type: sel_type.getValue('value'),
                };

                //执行重载
                table.reload(tableId, {
                    method: 'post',
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                  , where: temp
                }, 'data');
            }
            , zpjLoading: function (othis) {

                score = 0;
                $.ajax({
                    type: "post",
                    url: Root + 'Enterprise/GetEnterpriseZPJScore',
                    async: false,
                    success: function (data) {
                        if (data.SubmitResult) {
                            score = data.Object;
                        } else {
                            dialog.danger('操作失败！Error Message:' + data.Message);
                        }
                    },
                    error: function () {
                        dialog.danger('操作失败！请重试或者联系管理员');
                    },
                    complete: function () {

                    }
                });

                var DISABLED = 'layui-btn-disabled';
                if (othis.hasClass(DISABLED)) return;

                //模拟loading
                var n = 0, timer = setInterval(function () {
                    n = n + Math.random() * 10 | 0;
                    if (n > score) {
                        n = score;
                        clearInterval(timer);
                        othis.removeClass(DISABLED);
                    }
                    var current_color = '';
                    var remove_color = '';
                    if (n > 80) {
                        remove_color = 'layui-bg-blue';
                        current_color = 'layui-bg-green';    //绿色
                    } else if (n > 60) {
                        remove_color = 'layui-bg-red';
                        current_color = 'layui-bg-blue';    //蓝色
                    } else if (n > 40) {
                        remove_color = 'layui-bg-orange';
                        current_color = 'layui-bg-red';   //红色
                    } else if (n > 20) {
                        remove_color = 'layui-bg-cyan';
                        current_color = 'layui-bg-orange';    //橙色
                    } else if (n > 0) {
                        current_color = 'layui-bg-cyan';  //灰色
                        //current_color = 'layui-bg-cyan';  //黑色
                    }
                    $('#zpjScore').children().eq(0).removeClass(remove_color);
                    $('#zpjScore').children().eq(0).addClass(current_color);

                    element.progress('zpjScore', n + '%');
                }, 300 + Math.random() * 1000);
                othis.addClass(DISABLED);
            }
        };

        $('#enterpriseDiv .layui-btn').on('click', function () {
            var othis = $(this), type = $(this).data('type');
            active[type] ? active[type].call(this, othis) : '';
        });

        zpActive.tableTool(table, layer, form, null, null, null, null, oInit.Delete, oInit.LoadTypeInit);

        //监听提交
        form.on('submit(save)', function (data) {
            var rs = oInit.Save(data.field);    //保存数据
            if (rs) {
                active.reload();    //重新加载table数据
                layer.closeAll();   //关闭弹出层
            }
            return false;   //true刷新当前页面
        });
    }

    oInit.GetInvestorData = function () {
        var investorDate = [];
        //加载企业相关所有数据
        $.ajax({
            type: "post",
            async: false,
            url: Root + 'Enterprise/GetEnterpriseInvestor',
            success: function (result) {
                if (result.code == 0) {
                    investorDate = result.data;
                } else {
                    dialog.danger(result.msg);
                }
            },
            error: function () {
                dialog.danger('操作失败！请重试或者联系管理员');
            },
            complete: function () {
            }
        });
        return investorDate;
    }

    oInit.GetProductData = function () {
        var dataList = [];
        //加载企业相关所有数据
        $.ajax({
            type: "post",
            async: false,
            url: Root + 'Enterprise/GetEnterpriseProduct',
            success: function (result) {
                if (result.code == 0) {
                    dataList = result.data;
                } else {
                    dialog.danger(result.msg);
                }
            },
            error: function () {
                dialog.danger('操作失败！请重试或者联系管理员');
            },
            complete: function () {
            }
        });
        return dataList;
    }

    oInit.GetPersonnelData = function () {
        var dataList = [];
        //加载企业相关所有数据
        $.ajax({
            type: "post",
            async: false,
            url: Root + 'Enterprise/GetEnterprisePersonnalInfo',
            success: function (result) {
                if (result.code == 0) {
                    dataList = result.data;
                } else {
                    dialog.danger(result.msg);
                }
            },
            error: function () {
                dialog.danger('操作失败！请重试或者联系管理员');
            },
            complete: function () {
            }
        });
        return dataList;
    }

    oInit.GetSupportData = function () {
        var dataList = [];
        //加载企业相关所有数据
        $.ajax({
            type: "post",
            async: false,
            url: Root + 'Enterprise/GetEnterpriseSupportInfo',
            success: function (result) {
                if (result.code == 0) {
                    dataList = result.data;
                } else {
                    dialog.danger(result.msg);
                }
            },
            error: function () {
                dialog.danger('操作失败！请重试或者联系管理员');
            },
            complete: function () {
            }
        });
        return dataList;
    }

    oInit.investorData = function (formData) {
        if (formData == null) {
            var tr_count = $('#tb_investor tbody').find('tr').length;
            if (tr_count >= 5) {
                toastr.error('不能超过5条信息哦~');
                return;
            }
            //formData = [{ 'ep_id': '', 'inv_name': '', 'inv_money': '', 'inv_mode': '', 'inv_percent': '', 'inv_jointime': '', 'inv_cert_type': '', 'inv_cert_no': '' }];
            formData = [{}];
        }
        var idx = 1;
        if ($('#tb_investor tbody').find('tr').length > 0) {
            var last_radio_index = $('#tb_investor_body').find('tr').eq($('#tb_investor_body').find('tr').length - 1).find('[type="radio"]').attr('value');
            idx = parseInt(last_radio_index) + 1;
        }
        //方法级渲染
        $.each(formData, function (i, item) {
            //$('#tmp_inv_mode option').attr("selected", false);
            //$('#tmp_inv_mode option[value="' + (item.inv_mode == undefined ? '' : item.inv_mode) + '"]').attr("selected", true);
            //var optionHtml = $('#tmp_inv_mode').html();
            //var inv_mode_html = '<select name="ep_investor.inv_mode">' + optionHtml + '</select>';
            var tmp_inv_mode_html = oInit.getSelectOptionsHtml('tmp_inv_mode', (item.inv_mode == undefined ? '' : item.inv_mode), 'ep_investor.inv_mode');
            var tmp_inv_cert_type = oInit.getSelectOptionsHtml('tmp_inv_cert_type', (item.inv_cert_type == undefined ? '' : item.inv_cert_type), 'ep_investor.inv_cert_type');

            var tr_html = ['<tr>',
                    '<td style="text-align:center;"><input type="radio" name="rdo" value="' + (idx + i) + '" ></td>',
                    //'<td style="text-align:center;">' + (idx + i) + '</td>',
                    '<td><input type="text" class="layui-input" name="ep_investor.inv_name" maxlength="25" value="' + (item.inv_name == undefined ? '' : item.inv_name) + '" /></td>',
                    '<td><input type="number" class="layui-input" name="ep_investor.inv_money" value="' + (item.inv_money == undefined ? '' : item.inv_money) + '" min="0" step="0.01" /></td>',
                    '<td>' + tmp_inv_mode_html + '</td>',
                    '<td><input type="number" class="layui-input" name="ep_investor.inv_percent" value="' + (item.inv_percent == undefined ? '' : item.inv_percent) + '" min="0" step="0.01"/></td>',
                    '<td><input type="date" class="layui-input" name="ep_investor.inv_jointime" value="' + (item.inv_jointime == undefined ? '' : changeDateFormat(item.inv_jointime)) + '" /></td>',
                    //'<td><input type="text" class="layui-input" name="ep_investor.inv_cert_type" value="' + (item.inv_cert_type == undefined ? '' : item.inv_cert_type) + '" /></td>',
                    '<td>' + tmp_inv_cert_type + '</td>',
                    '<td><input type="text" class="layui-input" name="ep_investor.inv_cert_no" maxlength="18" value="' + (item.inv_cert_no == undefined ? '' : item.inv_cert_no) + '" /></td>',
                '</tr>'].join('');
            //$('[lay-id="tb_investor"] .layui-table-main tbody').append(tr_html);
            $('#tb_investor tbody').append(tr_html);
        });
        form.render();  //渲染form 否则select radio等元素不显示
    }

    oInit.productData = function (formData) {
        var tb_id = 'tb_product';
        var tb_body = 'tb_product_body';
        var tb_name = 'ep_business_product.';
        if (formData == null) {
            var tr_count = $('#' + tb_id + ' tbody').find('tr').length;
            if (tr_count >= 5) {
                toastr.error('不能超过8条信息哦~');
                return;
            }
            formData = [{}];
        }
        var idx = 1;
        if ($('#' + tb_id + ' tbody').find('tr').length > 0) {
            var last_radio_index = $('#' + tb_body).find('tr').eq($('#' + tb_body).find('tr').length - 1).find('[type="radio"]').attr('value');
            idx = parseInt(last_radio_index) + 1;
        }
        //方法级渲染
        $.each(formData, function (i, item) {
            var tmp_prod_type = oInit.getSelectOptionsHtml('tmp_prod_type', (item.prod_type == undefined ? '' : item.prod_type), '' + tb_name + 'prod_type');

            var tr_html = ['<tr>',
                    '<td style="text-align:center;"><input type="radio" name="rdo" value="' + (idx + i) + '" ></td>',
                    //'<td style="text-align:center;">' + (idx + i) + '</td>',
                    '<td><input type="text" class="layui-input" name="' + tb_name + 'prod_name" maxlength="25" value="' + (item.prod_name == undefined ? '' : item.prod_name) + '" /></td>',
                    '<td>' + tmp_prod_type + '</td>',
                    '<td><input type="number" class="layui-input" name="' + tb_name + 'prod_sale_revenue" value="' + (item.prod_sale_revenue == undefined ? '' : item.prod_sale_revenue) + '" min="0" step="0.01"/></td>',
                    '<td><input type="number" class="layui-input" name="' + tb_name + 'prod_profit_tax" value="' + (item.prod_profit_tax == undefined ? '' : item.prod_profit_tax) + '" min="0" step="0.01"/></td>',
                '</tr>'].join('');
            $('#' + tb_id + ' tbody').append(tr_html);
        });
        form.render();  //渲染form 否则select radio等元素不显示
    }

    oInit.personnelData = function (formData) {
        var tb_id = 'tb_personnel_info';
        var tb_body = 'tb_personnel_info_body';
        var tb_name = 'ep_personnel_info.';
        if (formData == null) {
            var tr_count = $('#' + tb_id + ' tbody').find('tr').length;
            if (tr_count >= 5) {
                toastr.error('不能超过8条信息哦~');
                return;
            }
            formData = [{}];
        }
        var idx = 1;
        if ($('#' + tb_id + ' tbody').find('tr').length > 0) {
            var last_radio_index = $('#' + tb_body).find('tr').eq($('#' + tb_body).find('tr').length - 1).find('[type="radio"]').attr('value');
            idx = parseInt(last_radio_index) + 1;
        }
        var formDataLength = formData.length;
        if (formDataLength == 0) {
            formData = [{}, {}];//如果没有数据初始化两条数据
        }
        //方法级渲染
        $.each(formData, function (i, item) {
            var tmp_pi_education = oInit.getSelectOptionsHtml('tmp_pi_education', (item.pi_education == undefined ? '' : item.pi_education), '' + tb_name + 'pi_education');
            var tmp_pi_id_type = oInit.getSelectOptionsHtml('tmp_pi_id_type', (item.pi_id_type == undefined ? '' : item.pi_id_type), '' + tb_name + 'pi_id_type');
            var tmp_pi_title = oInit.getSelectOptionsHtml('tmp_pi_title', (item.pi_title == undefined ? '' : item.pi_title), '' + tb_name + 'pi_title');

            var tr_html = ['<tr>',
                    //'<td style="text-align:center;"><input type="radio" name="rdo" value="' + (idx + i) + '" ></td>',
                    //'<td style="text-align:center;">' + (idx + i) + '</td>',
                    '<td><input type="text" class="layui-input" name="' + tb_name + 'pi_type" value="' + (item.pi_type == undefined ? (i == 0 ? "法定代表人" : "单位负责人") : item.pi_type) + '" /></td>',
                    '<td><input type="text" class="layui-input" name="' + tb_name + 'pi_name" value="' + (item.pi_name == undefined ? '' : item.pi_name) + '" /></td>',
                    '<td>' + tmp_pi_education + '</td>',
                    '<td><input type="text" class="layui-input" name="' + tb_name + 'pi_mobile" value="' + (item.pi_mobile == undefined ? '' : item.pi_mobile) + '" /></td>',
                    '<td><input type="text" class="layui-input" name="' + tb_name + 'pi_phone" value="' + (item.pi_phone == undefined ? '' : item.pi_phone) + '" /></td>',
                    '<td>' + tmp_pi_id_type + '</td>',
                    '<td><input type="text" class="layui-input" name="' + tb_name + 'pi_id_no" value="' + (item.pi_id_no == undefined ? '' : item.pi_id_no) + '" /></td>',
                    '<td><input type="text" class="layui-input" name="' + tb_name + 'pi_job" value="' + (item.pi_job == undefined ? '' : item.pi_job) + '" /></td>',
                    '<td>' + tmp_pi_title + '</td>', ,
                '</tr>'].join('');
            $('#' + tb_id + ' tbody').append(tr_html);
        });
        form.render();  //渲染form 否则select radio等元素不显示
    }

    oInit.supportData = function (formData) {
        var tb_id = 'tb_support';
        var tb_body = 'tb_support_body';
        var tb_name = 'ep_support_info.';
        if (formData == null) {
            var tr_count = $('#' + tb_id + ' tbody').find('tr').length;
            formData = [{}];
        }
        var idx = 1;
        if ($('#' + tb_id + ' tbody').find('tr').length > 0) {
            var last_radio_index = $('#' + tb_body).find('tr').eq($('#' + tb_body).find('tr').length - 1).find('[type="radio"]').attr('value');
            idx = parseInt(last_radio_index) + 1;
        }
        //方法级渲染
        $.each(formData, function (i, item) {
            var tmp_sup_type = oInit.getSelectOptionsHtml('tmp_sup_type', (item.sup_type == undefined ? '' : item.sup_type), '' + tb_name + 'sup_type');
            var tmp_sup_postponed = oInit.getSelectOptionsHtml('tmp_sup_postponed', (item.sup_postponed == undefined ? '' : item.sup_postponed), '' + tb_name + 'sup_postponed');

            var tr_html = ['<tr>',
                    '<td style="text-align:center;"><input type="radio" name="rdo" value="' + (idx + i) + '" ></td>',
                    //'<td style="text-align:center;">' + (idx + i) + '</td>',
                    '<td>' + tmp_sup_type + '</td>',
                    '<td><input type="text" class="layui-input" name="' + tb_name + 'sup_name" value="' + (item.sup_name == undefined ? '' : item.sup_name) + '" /></td>',
                    '<td><input type="number" class="layui-input" name="' + tb_name + 'sup_year" value="' + (item.sup_year == undefined ? '' : item.sup_year) + '" maxlength="4" max="2100" min="1900" step="1"/></td>',
                    '<td><input type="number" class="layui-input" name="' + tb_name + 'sup_proj_money" value="' + (item.sup_proj_money == undefined ? '' : item.sup_proj_money) + '" min="0" step="0.01"/></td>',
                    '<td><input type="number" class="layui-input" name="' + tb_name + 'sup_app_money" value="' + (item.sup_app_money == undefined ? '' : item.sup_app_money) + '" min="0" step="0.01"/></td>',
                    '<td><input type="date" class="layui-input" name="' + tb_name + 'sup_proj_start" value="' + (item.sup_proj_start == undefined ? '' : changeDateFormat(item.sup_proj_start)) + '" />',
                    '~<input type="date" class="layui-input" name="' + tb_name + 'sup_proj_end" value="' + (item.sup_proj_end == undefined ? '' : changeDateFormat(item.sup_proj_end)) + '" /></td>',
                    '<td>' + tmp_sup_postponed + '</td>',
                    '<td><input type="date" class="layui-input" name="' + tb_name + 'sup_postponed_start" value="' + (item.sup_postponed_start == undefined ? '' : changeDateFormat(item.sup_postponed_start)) + '" />',
                    '~<input type="date" class="layui-input" name="' + tb_name + 'sup_postponed_end" value="' + (item.sup_postponed_end == undefined ? '' : changeDateFormat(item.sup_postponed_end)) + '" /></td>',
                '</tr>'].join('');
            $('#' + tb_id + ' tbody').append(tr_html);
        });
        form.render();  //渲染form 否则select radio等元素不显示
    }

    oInit.getSelectOptionsHtml = function (id, curValue, columnName) {
        var select_html = '';
        $('#' + id + ' option').attr("selected", false);
        $('#' + id + ' option[value="' + curValue + '"]').attr("selected", true);
        var optionHtml = $('#' + id + '').html();
        select_html = '<select name="' + columnName + '" lay-search="">' + optionHtml + '</select>';
        return select_html;
    }

    oInit.loadPageData = function () {
        //获得荣誉集合并加载企业的荣誉信息
        $.ajax({
            type: "post",
            //async: false,
            url: Root + 'EPHonor/GetEPHonorList',
            //data: { type: type },
            success: function (result) {
                if (result.SubmitResult) {
                    //加载：企业荣誉获得情况
                    var list = result.Object;
                    if (list == null || list.length == 0) {
                        return;
                    }
                    var rongyuTable = $('#rongyuTable');
                    rongyuTable.html('');
                    var th_html = '<tr>';
                    var td_html = '<tr>';
                    var tbody_html = '';
                    var title_html = '';
                    $.each(list, function (i, item) {

                        var ht_type = item.ht_honor_title.ht_type;
                        var ht_is = item.ep_ht == null ? false : item.ep_ht.ht_is;
                        var ht_id = item.ht_honor_title.ht_id;
                        if (ht_type == 1) {
                            title_html = '<a href="javascript:;" name="a_title" data-htid="' + ht_id + '" class="' + (ht_is ? '' : 'layui-btn-disabled') + '"><i class="layui-icon layui-icon-link"></i>' + item.ht_honor_title.ht_title + '</a>';
                        } else {
                            title_html = item.ht_honor_title.ht_title;
                        }
                        th_html += '<th style="text-align: center;">' + title_html + '</th>';

                        var id = item.ep_ht == null ? '' : item.ep_ht.id;
                        var ht_pid = item.ht_honor_title.ht_pid;
                        var ht_content = item.ep_ht == null ? '' : item.ep_ht.ht_content == null ? '' : item.ep_ht.ht_content;
                        var ht_count = item.ep_ht == null ? '' : item.ep_ht.ht_count == null ? '' : item.ep_ht.ht_count;

                        var td_content = '';
                        td_content = '<input type="hidden" name="id" value="' + id + '" />';
                        td_content += '<input type="hidden" name="ht_id" value="' + ht_id + '" />';
                        td_content += '<input type="hidden" name="ht_type" value="' + ht_type + '" />';
                        if (ht_type == 1) {
                            td_content += '<select name="ht_is" lay-filter="ht_is" data-httype="' + ht_type + '" data-htid="' + ht_id + '"><option value="0" ' + (!ht_is ? 'selected' : '') + '>否</option><option value="1" ' + (ht_is ? 'selected' : '') + '>是</option></select>';
                        } else if (ht_type == 2) {
                            if (ht_pid == null) {
                                td_content += '<select name="ht_is" lay-filter="ht_is" data-httype="' + ht_type + '" data-htid="' + ht_id + '"><option value="0" ' + (!ht_is ? 'selected' : '') + '>否</option><option value="1" ' + (ht_is ? 'selected' : '') + '>是</option></select>';
                            } else {

                                var pidIsTrue = $.grep(list, function (child) {
                                    return child.ep_ht != null && child.ep_ht.ht_is && child.ht_honor_title.ht_id == ht_pid;
                                });
                                var readonly = pidIsTrue != null && pidIsTrue.length > 0 ? '' : 'layui-btn-disabled';
                                td_content += '<input type="text" name="ht_content" value="' + ht_content + '" data-htid="' + ht_id + '" data-pid="' + ht_pid + '" autocomplete="off" class="layui-input ' + readonly + '" ' + (readonly == '' ? '' : 'readonly') + '>';
                            }
                        } else if (ht_type == 3) {
                            td_content += '<input type="number" name="ht_count" value="' + ht_count + '" min="0" step="1" value="0" autocomplete="off" class="layui-input">';
                        }

                        td_html += '<td>' + td_content + '</td>';

                        //每6个td或list循环完，结束行
                        if ((i + 1) % 6 == 0 || (i + 1) == list.length) {
                            th_html += '</tr>';
                            td_html += '</tr>';
                            tbody_html += th_html + td_html;

                            //循环未结束，开启新行
                            if ((i + 1) < list.length) {
                                th_html = '<tr>';
                                td_html = '<tr>';
                            }
                        }
                    });
                    rongyuTable.append(tbody_html);
                } else {
                    dialog.danger(result.Message);
                }
            },
            error: function () {
                dialog.danger('操作失败！请重试或者联系管理员');
            },
            complete: function () {
                form.render();
            }
        });

        //加载企业相关所有数据
        $.ajax({
            type: "post",
            //async: false,
            url: Root + 'Enterprise/GetEnterprise',
            //data: { type: type },
            success: function (result) {
                if (result.SubmitResult) {
                    //加载：企业荣誉获得情况
                    var data = result.Object;
                    if (data == null || data.length == 0) {
                        return;
                    }
                    SetFormValues("#enterpriseDiv", data, "name");

                    //企业近三年基本数据
                    var ep_basic_data_Tbody = $('#ep_basic_data_Tbody tr:eq(0)');
                    //ep_basic_data_Tbody.html('');
                    data.ep_basic_data.push({});
                    $.each(data.ep_basic_data, function (i, item) {
                        $('#lb_year' + i).html(item.data_year);
                        var basuc_data_HTML = ['<td style="border-left: 1px solid rgb(255, 255, 255); padding: 0px;text-align: center;"><input type="hidden" name="id" />'
, '<div class="td_item">' + (item.ep_id == undefined ? '<span id="avg_data_yy_total"></span>' : '<input type="number" name="ep_basic_data.data_yy_total" value="' + item.data_yy_total + '" class="layui-input" />') + '</div>'
, '<div class="td_item">' + (item.ep_id == undefined ? '<span id="avg_data_yy_zyyw"></span>' : '<input type="number" name="ep_basic_data.data_yy_zyyw" value="' + item.data_yy_zyyw + '" class="layui-input">') + '</div>'
, '<div class="td_item">' + (item.ep_id == undefined ? '<span id="avg_data_yy_gxjscp"></span>' : '<input type="number" name="ep_basic_data.data_yy_gxjscp" value="' + item.data_yy_gxjscp + '" class="layui-input">') + '</div>'
, '<div class="td_item">' + (item.ep_id == undefined ? '<span id="avg_data_yy_xcpxs"></span>' : '<input type="number" name="ep_basic_data.data_yy_xcpxs" value="' + item.data_yy_xcpxs + '" class="layui-input">') + '</div>'
, '<div class="td_item">' + (item.ep_id == undefined ? '<span id="avg_data_yy_rjcpfw"></span>' : '<input type="number" name="ep_basic_data.data_yy_rjcpfw" value="' + item.data_yy_rjcpfw + '" class="layui-input">') + '</div>'
, '<div class="td_item">' + (item.ep_id == undefined ? '<span id="avg_data_zcz_total"></span>' : '<input type="number" name="ep_basic_data.data_zcz_total" value="' + item.data_zcz_total + '" class="layui-input">') + '</div>'
, '<div class="td_item">' + (item.ep_id == undefined ? '<span id="avg_data_zcz_gxjscp"></span>' : '<input type="number" name="ep_basic_data.data_zcz_gxjscp" value="' + item.data_zcz_gxjscp + '" class="layui-input">') + '</div>'
, '<div class="td_item">' + (item.ep_id == undefined ? '<span id="avg_data_zcz_zzzscq"></span>' : '<input type="number" name="ep_basic_data.data_zcz_zzzscq" value="' + item.data_zcz_zzzscq + '" class="layui-input">') + '</div>'
, '<div class="td_item">' + (item.ep_id == undefined ? '<span id="avg_data_zjz_total"></span>' : '<input type="number" name="ep_basic_data.data_zjz_total" value="' + item.data_zjz_total + '" class="layui-input">') + '</div>'
, '<div class="td_item">' + (item.ep_id == undefined ? '<span id="avg_data_zjz_ldzbc"></span>' : '<input type="number" name="ep_basic_data.data_zjz_ldzbc" value="' + item.data_zjz_ldzbc + '" class="layui-input">') + '</div>'
, '<div class="td_item">' + (item.ep_id == undefined ? '<span id="avg_data_zjz_gdzczj"></span>' : '<input type="number" name="ep_basic_data.data_zjz_gdzczj" value="' + item.data_zjz_gdzczj + '" class="layui-input">') + '</div>'
, '<div class="td_item">' + (item.ep_id == undefined ? '<span id="avg_data_zjz_scjse"></span>' : '<input type="number" name="ep_basic_data.data_zjz_scjse" value="' + item.data_zjz_scjse + '" class="layui-input">') + '</div>'
, '<div class="td_item">' + (item.ep_id == undefined ? '<span id="avg_data_zjz_yyyy"></span>' : '<input type="number" name="ep_basic_data.data_zjz_yyyy" value="' + item.data_zjz_yyyy + '" class="layui-input">') + '</div>'
, '<div class="td_item">' + (item.ep_id == undefined ? '<span id="avg_data_gxjscpfjz_total"></span>' : '<input type="number" name="ep_basic_data.data_gxjscpfjz_total" value="' + item.data_gxjscpfjz_total + '" class="layui-input">') + '</div>'
, '<div class="td_item">' + (item.ep_id == undefined ? '<span id="avg_data_ckze_total"></span>' : '<input type="number" name="ep_basic_data.data_ckze_total" value="' + item.data_ckze_total + '" class="layui-input">') + '</div>'
, '<div class="td_item">' + (item.ep_id == undefined ? '<span id="avg_data_ckze_gxjscpcke"></span>' : '<input type="number" name="ep_basic_data.data_ckze_gxjscpcke" value="' + item.data_ckze_gxjscpcke + '" class="layui-input">') + '</div>'
, '<div class="td_item">' + (item.ep_id == undefined ? '<span id="avg_data_zyywlr_total"></span>' : '<input type="number" name="ep_basic_data.data_zyywlr_total" value="' + item.data_zyywlr_total + '" class="layui-input">') + '</div>'
, '<div class="td_item">' + (item.ep_id == undefined ? '<span id="avg_data_lrze_total"></span>' : '<input type="number" name="ep_basic_data.data_lrze_total" value="' + item.data_lrze_total + '" class="layui-input">') + '</div>'
, '<div class="td_item">' + (item.ep_id == undefined ? '<span id="avg_data_jlr_total"></span>' : '<input type="number" name="ep_basic_data.data_jlr_total" value="' + item.data_jlr_total + '" class="layui-input">') + '</div>'
, '<div class="td_item">' + (item.ep_id == undefined ? '<span id="avg_data_jlr_gxjscpjlr"></span>' : '<input type="number" name="ep_basic_data.data_jlr_gxjscpjlr" value="' + item.data_jlr_gxjscpjlr + '" class="layui-input">') + '</div>'
, '<div class="td_item">' + (item.ep_id == undefined ? '<span id="avg_data_sjsjsf_total"></span>' : '<input type="number" name="ep_basic_data.data_sjsjsf_total" value="' + item.data_sjsjsf_total + '" class="layui-input">') + '</div>'
, '<div class="td_item">' + (item.ep_id == undefined ? '<span id="avg_data_sjsjsf_zzs"></span>' : '<input type="number" name="ep_basic_data.data_sjsjsf_zzs" value="' + item.data_sjsjsf_zzs + '" class="layui-input">') + '</div>'
, '<div class="td_item">' + (item.ep_id == undefined ? '<span id="avg_data_sjsjsf_yys"></span>' : '<input type="number" name="ep_basic_data.data_sjsjsf_yys" value="' + item.data_sjsjsf_yys + '" class="layui-input">') + '</div>'
, '<div class="td_item">' + (item.ep_id == undefined ? '<span id="avg_data_sjsjsf_qysds"></span>' : '<input type="number" name="ep_basic_data.data_sjsjsf_qysds" value="' + item.data_sjsjsf_qysds + '" class="layui-input">') + '</div>'
, '<div class="td_item">' + (item.ep_id == undefined ? '<span id="avg_data_sjsjsf_grsds"></span>' : '<input type="number" name="ep_basic_data.data_sjsjsf_grsds" value="' + item.data_sjsjsf_grsds + '" class="layui-input">') + '</div>'
, '<div class="td_item">' + (item.ep_id == undefined ? '<span id="avg_data_sjsjsf_qts"></span>' : '<input type="number" name="ep_basic_data.data_sjsjsf_qts" value="' + item.data_sjsjsf_qts + '" class="layui-input">') + '</div>'
, '<div class="td_item">' + (item.ep_id == undefined ? '<span id="avg_data_sjjmhdksf_total"></span>' : '<input type="number" name="ep_basic_data.data_sjjmhdksf_total" value="' + item.data_sjjmhdksf_total + '" class="layui-input">') + '</div>'
, '<div class="td_item">' + (item.ep_id == undefined ? '<span id="avg_data_sjjmhdksf_zzs"></span>' : '<input type="number" name="ep_basic_data.data_sjjmhdksf_zzs" value="' + item.data_sjjmhdksf_zzs + '" class="layui-input">') + '</div>'
, '<div class="td_item">' + (item.ep_id == undefined ? '<span id="avg_data_sjjmhdksf_zzs_gdzcsbdk"></span>' : '<input type="number" name="ep_basic_data.data_sjjmhdksf_zzs_gdzcsbdk" value="' + item.data_sjjmhdksf_zzs_gdzcsbdk + '" class="layui-input">') + '</div>'
, '<div class="td_item">' + (item.ep_id == undefined ? '<span id="avg_data_sjjmhdksf_yys"></span>' : '<input type="number" name="ep_basic_data.data_sjjmhdksf_yys" value="' + item.data_sjjmhdksf_yys + '" class="layui-input">') + '</div>'
, '<div class="td_item">' + (item.ep_id == undefined ? '<span id="avg_data_sjjmhdksf_sds"></span>' : '<input type="number" name="ep_basic_data.data_sjjmhdksf_sds" value="' + item.data_sjjmhdksf_sds + '" class="layui-input">') + '</div>'
, '<div class="td_item">' + (item.ep_id == undefined ? '<span id="avg_data_jmsze_total"></span>' : '<input type="number" name="ep_basic_data.data_jmsze_total" value="' + item.data_jmsze_total + '" class="layui-input">') + '</div>'
, '<div class="td_item">' + (item.ep_id == undefined ? '<span id="avg_data_jmsze_yfjjkcsdsjm"></span>' : '<input type="number" name="ep_basic_data.data_jmsze_yfjjkcsdsjm" value="' + item.data_jmsze_yfjjkcsdsjm + '" class="layui-input">') + '</div>'
, '<div class="td_item">' + (item.ep_id == undefined ? '<span id="avg_data_jmsze_gxjsqyjms"></span>' : '<input type="number" name="ep_basic_data.data_jmsze_gxjsqyjms" value="' + item.data_jmsze_gxjsqyjms + '" class="layui-input">') + '</div>'
, '<div class="td_item">' + (item.ep_id == undefined ? '<span id="avg_data_yfjjkc_total"></span>' : '<input type="number" name="ep_basic_data.data_yfjjkc_total" value="' + item.data_yfjjkc_total + '" class="layui-input">') + '</div>'
, '<div class="td_item">' + (item.ep_id == undefined ? '<span id="avg_data_nxse_total"></span>' : '<input type="number" name="ep_basic_data.data_nxse_total" value="' + item.data_nxse_total + '" class="layui-input">') + '</div>'
, '<div class="td_item">' + (item.ep_id == undefined ? '<span id="avg_data_cpxssr_total"></span>' : '<input type="number" name="ep_basic_data.data_cpxssr_total" value="' + item.data_cpxssr_total + '" class="layui-input">') + '</div>'
, '<div class="td_item">' + (item.ep_id == undefined ? '<span id="avg_data_yfjfzc_total"></span>' : '<input type="number" name="ep_basic_data.data_yfjfzc_total" value="' + item.data_yfjfzc_total + '" class="layui-input">') + '</div>'
, '<div class="td_item">' + (item.ep_id == undefined ? '<span id="avg_data_total_assets"></span>' : '<input type="number" name="ep_basic_data.data_total_assets" value="' + item.data_total_assets + '" class="layui-input">') + '</div>'
, '<div class="td_item">' + (item.ep_id == undefined ? '<span id="avg_data_yfjfzc_yyyfyqhsbzc"></span>' : '<input type="number" name="ep_basic_data.data_yfjfzc_yyyfyqhsbzc" value="' + item.data_yfjfzc_yyyfyqhsbzc + '" class="layui-input">') + '</div>'
, '<div class="td_item">' + (item.ep_id == undefined ? '<span id="avg_data_gdzcyz_total"></span>' : '<input type="number" name="ep_basic_data.data_gdzcyz_total" value="' + item.data_gdzcyz_total + '" class="layui-input">') + '</div>'
, '<div class="td_item">' + (item.ep_id == undefined ? '<span id="avg_data_nmzcze_total"></span>' : '<input type="number" name="ep_basic_data.data_nmzcze_total" value="' + item.data_nmzcze_total + '" class="layui-input">') + '</div>'
, '<div class="td_item">' + (item.ep_id == undefined ? '<span id="avg_data_nmgdzczz_total"></span>' : '<input type="number" name="ep_basic_data.data_nmgdzczz_total" value="' + item.data_nmgdzczz_total + '" class="layui-input">') + '</div>'
, '<div class="td_item">' + (item.ep_id == undefined ? '<span id="avg_data_nmfzze_total"></span>' : '<input type="number" name="ep_basic_data.data_nmfzze_total" value="' + item.data_nmfzze_total + '" class="layui-input">') + '</div>'
, '<div class="td_item">' + (item.ep_id == undefined ? '<span id="avg_data_zxjllje_total"></span>' : '<input type="number" name="ep_basic_data.data_zxjllje_total" value="' + item.data_zxjllje_total + '" class="layui-input">') + '</div>'
, '<div class="td_item">' + (item.ep_id == undefined ? '<span id="avg_data_jyhdxjllje_total"></span>' : '<input type="number" name="ep_basic_data.data_jyhdxjllje_total" value="' + item.data_jyhdxjllje_total + '" class="layui-input">') + '</div>'
, '<div class="td_item">' + (item.ep_id == undefined ? '<span id="avg_data_jyhdxjlrze_total"></span>' : '<input type="number" name="ep_basic_data.data_jyhdxjlrze_total" value="' + item.data_jyhdxjlrze_total + '" class="layui-input">') + '</div>'
, '<div class="td_item">' + (item.ep_id == undefined ? '<span id="avg_data_jyhdxjlcze_total"></span>' : '<input type="number" name="ep_basic_data.data_jyhdxjlcze_total" value="' + item.data_jyhdxjlcze_total + '" class="layui-input">') + '</div>'
, '<div class="td_item">' + (item.ep_id == undefined ? '<span id="avg_data_zcfzl_total"></span>' : '<input type="number" name="ep_basic_data.data_zcfzl_total" value="' + item.data_zcfzl_total + '" class="layui-input">') + '</div>'
                                , '</td>'].join('');
                        ep_basic_data_Tbody.append(basuc_data_HTML);
                    });

                    oInit.DataAvgCalculate();
                } else {
                    dialog.danger(result.Message);
                }
            },
            error: function () {
                dialog.danger('操作失败！请重试或者联系管理员');
            },
            complete: function () {
                form.render();
                oInit.InitSwitch();
            }
        });
    }

    oInit.DataAvgCalculate = function () {
        //计算平均增长率
        //1.如果第一年为0则不计算
        var td1_items = $('#ep_basic_data_Tbody tr:eq(0)').children('td:eq(1)').find('.td_item');
        var td2_items = $('#ep_basic_data_Tbody tr:eq(0)').children('td:eq(2)').find('.td_item');
        var td3_items = $('#ep_basic_data_Tbody tr:eq(0)').children('td:eq(3)').find('.td_item');
        var td4_items = $('#ep_basic_data_Tbody tr:eq(0)').children('td:eq(4)').find('.td_item');

        var input1;
        var input2;
        var input3;
        var span4;
        var nan = false;

        var f_input1 = 0;
        var f_input2 = 0;
        var f_input3 = 0;

        var growthRate1;
        var growthRate2;
        var avg_growthRate;
        $.each(td1_items, function (i, item) {
            input1 = td1_items.find('[type="number"]').eq(i);
            input2 = td2_items.find('[type="number"]').eq(i);
            input3 = td3_items.find('[type="number"]').eq(i);
            if (isNaN(parseFloat(input1.val())) || parseFloat(input1.val()) == 0) {
                input1.val(0);
                nan = true;
            }
            if (isNaN(parseFloat(input2.val())) || parseFloat(input2.val()) == 0) {
                input2.val(0);
            }
            if (isNaN(parseFloat(input3.val())) || parseFloat(input3.val()) == 0) {
                input3.val(0);
            }
            if (nan) {
                nan = false;
                return;
            }
            f_input1 = parseFloat(input1.val())
            f_input2 = parseFloat(input2.val())
            f_input3 = parseFloat(input3.val())

            //if (f_input1 == 1) {
            //    debugger
            //}
            //2.获得第二年和第一年的增长率
            //growthRate1 = (f_input2 - f_input1) / f_input1;
            if (f_input1 != "" && f_input2 != "" && f_input1 != "-" && f_input2 != "-" && f_input1 != "由系统统计" && f_input2 != "由系统统计") {
                if (parseFloat(f_input1) != 0) {
                    var rateVal = parseFloat((parseFloat(f_input2) - parseFloat(f_input1)) / Math.abs(parseFloat(f_input1)) * 100).toFixed(2);
                    growthRate1 = rateVal;
                } else {
                    growthRate1 = '';
                }
            }
            //3.获得第三年和第二年的增长率
            //growthRate2 = (f_input2 == 0 && f_input3 == 0) ? 0 : ((f_input3 - f_input2) / f_input2); //TODO  如何 2 0 4 等于 41.42%
            
            if (f_input2 != "" && f_input3 != "" && f_input2 != "-" && f_input3 != "-" && f_input2 != "由系统统计" && f_input3 != "由系统统计") {
                if (parseFloat(f_input2) != 0) {
                    var rateVal = parseFloat((parseFloat(f_input3) - parseFloat(f_input2)) / Math.abs(parseFloat(f_input2)) * 100).toFixed(2);
                    growthRate2 = rateVal;
                } else {
                    growthRate2 = '';
                }
            }
            console.log(growthRate1)
            console.log(growthRate2)

            //4.将两次增长率取平均值
            span4 = td4_items.find('span').eq(i);
            if (growthRate1 == 0) {
                avg_growthRate = growthRate2 * 100;
            } else if (growthRate2 == 0) {
                avg_growthRate = growthRate1 * 100;
            } else {
                avg_growthRate = (growthRate2 + growthRate1) / 2 * 100;
            }
            span4.html(avg_growthRate.toFixed(2));
        });
    }

    oInit.LoadHonorFile = function (title, htid) {
        var ht_id = htid;
        title = title ? title : '';
        layer.open({
            type: 2 //默认0，页面层1，iframe层2
          , title: '【附件上传】' + title
          , skin: 'layui-layer-molv'
          , content: Root + 'EPHonor/UploadTitleFile?ht_id=' + ht_id
          , shadeClose: true
          , area: ['80%', '80%']    //宽高
          , maxmin: true
        });
    }

    oInit.InitUpload = function (btn_uploadId) {
        var loading = null;
        upload.render({
            elem: '#' + btn_uploadId
            , url: Root + 'PublicUpload/UploadAnalysisYYZZ' //改成您自己的上传接口
            , accept: 'file' //普通文件
            , before: function () {
                loading = layer.load(0, {
                    shade: false,
                    time: -1
                });
            }
            , done: function (res) {
                //console.log(res);
                if (res.SubmitResult) { //上传成功
                    //将图片信息加载到文本中
                    var obj = res.Object;
                    $('[name="ep_name"]').val(obj.words_result.单位名称.words);
                    $('[name="ep_uscn"]').val(obj.words_result.社会信用代码.words);
                    $('[name="ep_reg_type"]').val(obj.words_result.类型.words);
                    $('[name="ep_mailing_adr"]').val(obj.words_result.地址.words);
                    $('[name="ep_legal_rep"]').val(obj.words_result.法人.words);
                    //$('[name="ep_reg_cap"]').val(Nzh.decodeB(obj.words_result.注册资本.words));
                    $('[name="ep_reg_cap"]').val(parseInt(obj.words_result.注册资本.words));
                    var yyyyMMdd = obj.words_result.成立日期.words.replace(/年/, '-').replace(/月/, '-').replace(/日/, '');
                    $('[name="ep_reg_date"]').val(yyyyMMdd);
                    $('[name="ep_biz_date"]').val(obj.words_result.有效期.words);
                    $('[name="ep_biz_scope"]').val(obj.words_result.经营范围.words);
                    //obj.words_result.组成形式.words
                    //obj.words_result.证件编号.words
                }
                layer.close(loading);
            }, error: function () {
                layer.close(loading);
            }
        });
    }

    oInit.InitSwitch = function () {
        $('[lay-filter="switchRadio"]').each(function () {
            var obj = $(this);
            var name = obj.prop('name');
            var checked = obj.prop('checked');
            var value = obj.data('value');
            var child_obj = $('[name=' + name + '_child]');
            if (value == "1") {
                if (checked) {
                    child_obj.prop('disabled', false);
                    child_obj.css('background', '');
                    child_obj.parent().css('background', '');
                }
            } else {
                if (checked) {
                    child_obj.prop('disabled', true);
                    child_obj.css('background', '#D3D3D3');
                    child_obj.parent().css('background', '#D3D3D3');
                }
            }
        });
    }

    //保存-新增
    oInit.Save = function (formdata) {
        //var dto = decodeURIComponent(formdata, true);   //处理中文,后台需要解码
        //静态添加节点
        $.ajax({
            type: "post",
            url: Root + 'Enterprise/SaveEnterprise',
            //async: false,
            data: { dto: formdata },
            //traditional: true,    //是否使用传统的方式浅层序列化,若有数组参数或对象参数需要设置true!!!!!!
            success: function (data) {
                if (data.SubmitResult) {
                    dialog.success('保存成功！');
                } else {
                    dialog.danger('操作失败！Error Message:' + data.Message);
                }
            },
            error: function () {
                dialog.danger('操作失败！请重试或者联系管理员');
            },
            complete: function () {

            }
        });
    }

    //删除
    oInit.Delete = function (arr_obj) {
        $.ajax({
            type: "post",
            url: Root + 'FZParam/DeleteBaseParam',
            data: { dto: arr_obj },
            success: function (data) {
                if (data.SubmitResult) {
                    dialog.success('删除成功');
                    active.reload();
                } else {
                    dialog.danger('操作失败！Error Message:' + data.Message);
                }
            },
            error: function () {
                dialog.danger('操作失败！请重试或者联系管理员');
            },
            complete: function () {

            }
        });
    }

    //加载下拉参数类别数据
    let sel_type;
    oInit.LoadType = function (type, selId, typeValue, isMultiple) {
        typeValue = typeValue ? typeValue : "";
        $.ajax({
            type: "post",
            async: false,
            url: Root + 'FZParam/GetAllBaseParam',
            data: { type: type },
            success: function (data) {
                //selId = selId ? selId : '#selType,#sel_type';
                if (!selId || selId.length == 0) {
                    return;
                }

                var selectData = new Array();
                var select = $(selId);
                select.empty();
                $.each(data.data, function (i, item) {
                    var name = ShowParamType(item.type);
                    if (isMultiple) {
                        selectData.push({ name: name, value: item.type });
                    } else {
                        select.append('<option value="' + item.type + '">' + name + '</option>');
                    }
                });
                //select.val(typeValue);
                //select.selectpicker('refresh');
                if (isMultiple) {
                    sel_type = xmSelect.render({
                        el: selId,
                        tips: '请选择参数类别',
                        language: 'zn',
                        data: selectData
                    })
                }
            },
            error: function () {
                dialog.danger('操作失败！请重试或者联系管理员');
            },
            complete: function () {

            }
        });
    }

    oInit.LoadTypeInit = function () {
        oInit.LoadType('type', '#selType');    //加载下拉角色
    }

    return oInit;
}